﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KinConquer.Entities.Calculations
{
    public class HitPoints
    {
        public static void Calculate(ref Hero h)
        {
            h.MaxManaPoints = MP(h);
            h.ManaPoints = Math.Min(h.ManaPoints, h.MaxManaPoints);

            h.MaxHitPoints = HP(h);
            h.HitPoints = Math.Min(h.HitPoints, h.MaxHitPoints);
        }

        public static UInt32 MP(Hero h)
        {
            return MP(h.Spirit, h.Class);
        }

        public static UInt32 MP(UInt16 spi, UInt16 job)
        {
            byte ManaBoost = 5;
            sbyte JobID = (sbyte)(job / 10);
            if (JobID == 13 || JobID == 14)
            {
                sbyte chksum = (sbyte)(job % 10);
                if (chksum >= 0 && chksum <= 5)
                {
                    ManaBoost += (byte)(5 * (job - (JobID * 10)));
                }
            }
            return (UInt32)((spi * ManaBoost)/* + h.Equipment.ItemMP*/);
        }

        public static UInt32 HP(Hero h)
        {
            return HP(h.Strength, h.Agility, h.Spirit, h.Vitality, h.Class);
        }

        public static UInt32 HP(UInt16 str, UInt16 agi, UInt16 spi, UInt16 vit, UInt16 job)
        {
            const byte HitpointBoost = 24;
            UInt16 StatHP = (UInt16)Math.Floor((Double)
                (str * 3) +
                (agi * 3) +
                (spi * 3) +
                (vit * HitpointBoost));
            switch (job)
            {
                case 11: StatHP = (UInt16)Math.Floor(StatHP * 1.05F); break;
                case 12: StatHP = (UInt16)Math.Floor(StatHP * 1.08F); break;
                case 13: StatHP = (UInt16)Math.Floor(StatHP * 1.10F); break;
                case 14: StatHP = (UInt16)Math.Floor(StatHP * 1.12F); break;
                case 15: StatHP = (UInt16)Math.Floor(StatHP * 1.15F); break;
            }
            return StatHP;
        }
    }
}
